<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>坐席状态监控</title>
	<link rel="stylesheet" type="text/css" href="css/easyui.css">
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
	<script>
		$(function(){
			$('#test').datagrid({
				title:'坐席状态查询',
				iconCls:'icon-save',
				width:780,
				height:350,
				nowrap: true,
				autoRowHeight: false,
				striped: true,
				collapsible:true,
				url:'',
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'workno',
				columns:[
 				[
					{field:'workno',title:'工号',width:50,sortable:true},
					{field:'workname',title:'姓名',width:80,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'callincnt',title:'已经接听数',width:80,sortable:true},
					{field:'calloutcnt',title:'外呼成功数',width:80,sortable:true},
					{field:'queueid',title:'技能组',width:40,sortable:true},
					{field:'buttonoptions',title:'可监控？',width:40,sortable:true},
					{field:'callstate',title:'状态',width:40,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						},
						formatter: function(value,row,index){
							return {
								0: '签出',
								1: '就绪',
								2: '上线',
								3: '通话',
								31: '呼叫',
								32: '振铃',
								4: '忙',
								5: '保持',
								6: '咨询',
								7: '咨询',
								8: '会议',
								9: '监听',
								10: '插话',
								11: '上线忙'
							}[value] || value
						}
					},
					{field:'callstatetime',title:'状态保持时间',width:80,sortable:true},
					{field:'statetimelen',title:'状态保持时间',width:80,sortable:true},
					{field:'timelen',title:'通话总时长',width:80,sortable:true},
					{field:'opt',title:'操作',align:'center',
						formatter:function(value,rec){
						    var linkStr= "";
						    if( (rec.buttonoptions & 1) == 1)
						      linkStr="<a onclick= monitorAgent('"+rec.workno+"')  ><span style='color:green'>监听</span></a> ";
						      else
						      linkStr="<span style='color:gray'>监听</span>";
						     if( (rec.buttonoptions & 2) == 2) 
						     { 						        
						        linkStr +="<a onclick= logoutAgent('"+rec.workno+"')  ><span style='color:green'>&nbsp;&nbsp;签出</span></a> ";
						     }
						     else
						     { 
							     linkStr +="<span style='color:gray'>&nbsp;&nbsp;签出</span>";
                 }
 							return linkStr;
						}
					}
				]],
				pagination:true,
				rownumbers:true
			});

			var p = $('#test').datagrid('getPager');
			$(p).pagination({
				onBeforeRefresh:function(){
					alert('before refresh');
				}
			});
		});

	/**********************************************
		 * 获取坐席所在组全部坐席的状态， 
		 * @param callback_func 回调函数
		 * @param qId           队列id
		 * @param workno        工号或者姓名
		 * @param states   坐席状态集合
		 * @param toNext : 0 上一页，1 下一页
		 **********************************************/ 
		function searchAgentList(){
		//状态列表
			var states= ""; // "3,5,8,11";  //坐席工作状态集合
			var worknos = document.getElementById("worknos").value ;
			window.opener.FlashAgentX.sendAction('getAgcListState', { worknos: worknos })
			window.opener.agentgetflag = "2";
			setTimeout("onGetQueueAgcState()",1000);
		}

    function onGetQueueAgcState(){	
			var flag = window.opener.agentgetflag;
			if(flag=="2"){
				setTimeout("onGetQueueAgcState()",1000);
			}else if(flag=="1"){
				window.opener.agentgetflag = "0";
				var data1=window.opener.agentlists; 
				if(data1.totalnum == 0){
					alert("无记录");
				}else{
					$('#test').datagrid('loadData', data1.detail );
				}
			}
	   }  

	function monitorAgent(agentId)
	{
		window.opener.FlashAgentX.sendAction('monitor', { toseatno: agentId })   
	}

	//代签出
	function logoutAgent(agentId)
	{
	   window.opener.FlashAgentX.sendAction('tocheckout', { toseatno: agentId });
		setTimeout("searchAgentList()",3000);
	}
	</script>
</head>

<body>
	<h2>坐席状态监控</h2>
	<div style="margin:10px 0;">
	    <span>坐席工号串</span>
	    <span><input type="text" id="worknos" value="" > </span>
	    <input type ="button" value="查询" onclick="searchAgentList()" >   
	</div>
	<table id="test"></table>
</body>
</html>